package com.huidao.servlet.buyer;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Shoppingcart;
import com.huidao.entity.User;
import com.huidao.service.buyer.GetGoodsService;
import com.huidao.service.buyer.GetGoodsServiceImpl;
import com.huidao.service.buyer.ShoppingCartService;
import com.huidao.service.buyer.ShoppingCartServiceImpl;

/**
 * Servlet implementation class ShoppingcartListServlet
 */
public class ShoppingcartListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShoppingcartListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String keyName = request.getParameter("keyName");	
		System.out.println(keyName);
		String sid =request.getParameter("id");
		long id = 0;
		if(sid!=null){
			id=Long.parseLong(sid);
		}
		int currentpage = 1;
		String curr = request.getParameter("CurrentPage");
		if(curr!=null){
			currentpage = Integer.parseInt(curr);
		}
		ShoppingCartService ss = new ShoppingCartServiceImpl();
		int totalpage = ss.getShoppingcartListTotalPage(keyName, id);
		if(currentpage>totalpage){
			currentpage=totalpage;
		}
		List<Shoppingcart> shoppingcartList=ss.getShoppingcartList(currentpage,keyName, id);
		for (Shoppingcart shoppingcart : shoppingcartList) {
			System.out.println(shoppingcart.getUser().getUserShopName());
		}
		request.setAttribute("CurrentPage", currentpage);
		request.setAttribute("TotalPage", totalpage);
		request.setAttribute("shoppingcartList", shoppingcartList);
		request.setAttribute("id", sid);
		request.getRequestDispatcher("shoppingcartlist.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
